package com.yami.shop.user.common.service.impl;

import cn.hutool.core.util.StrUtil;
import com.yami.shop.bean.model.User;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.dao.UserMapper;
import com.yami.shop.security.common.enums.SysTypeEnum;
import com.yami.shop.security.common.manager.PasswordCheckManager;
import com.yami.shop.security.common.manager.PasswordManager;
import com.yami.shop.user.common.service.UserInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@RequiredArgsConstructor
public class UserInfoServiceImpl implements UserInfoService {

    private final UserMapper userMapper;

    private final PasswordManager passwordManager;

    private final PasswordCheckManager passwordCheckManager;
    
    
    @Override
    public void checkPayPassword(String userId, String payPassword) {
        User user = userMapper.selectById(userId);
        if (StrUtil.isEmpty(user.getPayPassword())) {
            throw new YamiShopBindException("yami.user.set.pay.pwd");
        }
        String decryptPassword = passwordManager.decryptPassword(payPassword);
        passwordCheckManager.checkPayPassword(SysTypeEnum.ORDINARY, userId, decryptPassword, user.getPayPassword());
    }
    
    
}
